package com.xishu.entity.shop;

import com.xishu.annotation.dao.DefaultValue;
import com.xishu.annotation.dao.FieldMapping;
import com.xishu.annotation.dao.Search;
import com.xishu.annotation.lang.Lang;
import com.xishu.annotation.oplog.OplogAnnotation;
import com.xishu.entity.AbstractEntity;
import com.xishu.entity.NameAndId;
import com.xishu.entity.oplog.OpName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.util.List;

@Entity(name = "discount_ticket")
@Table(indexes = {@Index(columnList = "name"), @Index(columnList = "code"), @Index(columnList = "companyId")})
@Data
public class DiscountTicket extends AbstractEntity implements OpName {
    private static final long serialVersionUID = 4755225606875307771L;

    @Transient
    private String opName;

    @ApiModelProperty(value = "优惠卷的名称")
//    @UniqueName
    @OplogAnnotation(fieldName = "优惠卷的名称")
    @Lang(key = "name")
    @Search(like = true)
    private String name;

    @ApiModelProperty(value = "优惠卷的名称")
    @Lang(key = "name")
    @OplogAnnotation(fieldName = "模板中文名")
    @Search(like = true)
    private String name_zh;

    @ApiModelProperty(value = "优惠卷的名称")
    @Lang(key = "name")
    @OplogAnnotation(fieldName = "模板英文文名")
    @Search(like = true)
    private String name_en;

    @ApiModelProperty(value = "模板")
    @OplogAnnotation(fieldName = "模板")
    private Boolean template;

    @ApiModelProperty(value = "模板的ID")
    private Long parentId;

    @ApiModelProperty(value = "优惠卷的编码")
    @OplogAnnotation(fieldName = "优惠卷的编码")
    private String code;

    @Transient
    @ApiModelProperty(value = "优惠卷列表")
    private List<String> codeList;

    @ApiModelProperty(value = "归属的餐厅公司")
    private Long companyId;

    @ApiModelProperty(value = "餐厅公司名称")
    @OplogAnnotation(fieldName = "餐厅公司名称")
    private String companyName;

    @Transient
    @ApiModelProperty(value = "分店的名称以及ID")
    @FieldMapping(desField = "shopJson", serialize = true)
    @DefaultValue(defaultValue = "")
    private List<NameAndId> shopList;

    @ApiModelProperty(value = "分店的名称以及ID")
    @FieldMapping(desField = "shopList", serialize = false, genericType = "com.xishu.entity.NameAndId")
    @Lob
    @Column(columnDefinition = "MEDIUMTEXT")
    private String shopJson;

    @Transient
    @ApiModelProperty(value = "适用的场景")
    @FieldMapping(desField = "sceneJson", serialize = true)
    @OplogAnnotation(fieldName = "适用的场景")
    @DefaultValue(defaultValue = "")
    private List<NameAndId> sceneList;

    @ApiModelProperty(value = "适用的场景")
    @FieldMapping(desField = "sceneList", serialize = false, genericType = "com.xishu.entity.NameAndId")
    @Lob
    @Column(columnDefinition = "MEDIUMTEXT")
    private String sceneJson;

    @ApiModelProperty(value = "优惠卷类型,1金额卷，2折扣卷，3消费后金额,4菜品免单券")
    @OplogAnnotation(fieldName = "优惠卷类型")
    private Integer ticketType;

    @ApiModelProperty(value = "优惠卷面值")
    @OplogAnnotation(fieldName = "优惠卷面值")
    private Double discountCash;

    @ApiModelProperty(value = "几折,比如8.5折，直接填写8.5")
    @OplogAnnotation(fieldName = "几折")
    private Double discount;

    @ApiModelProperty(value = "几折,比如8.5折，直接填写8.5")
    @OplogAnnotation(fieldName = "英文描述的几折")
    private Double discountEn;

    @ApiModelProperty(value = "消费后返金额百分比，与afterCash不能共存")
    @OplogAnnotation(fieldName = "消费后返金额百分比")
    private Double afterPercent;

    @ApiModelProperty(value = "消费后返金额，与afterCost不能共存")
    @OplogAnnotation(fieldName = "消费后返金额")
    private Double afterCash;

    @ApiModelProperty(value = "消费后返金额卷产生的优惠卷的最低消费金额")
    @OplogAnnotation(fieldName = "消费后返金额卷产生的优惠卷的最低消费金额")
    private Double afterAtLeast;

    @ApiModelProperty(value = "消费后返金额卷产生的优惠卷的有效天数")
    @OplogAnnotation(fieldName = "消费后返金额卷产生的优惠卷的有效天数")
    private Integer afterValidDay;

    @ApiModelProperty(value = "消费后返金额卷产生的优惠卷的使用场景")
    @Transient
    @FieldMapping(desField = "afterSceneJson", serialize = true)
    @DefaultValue(defaultValue = "")
    private List<NameAndId> afterSceneList;

    @ApiModelProperty(value = "消费后返金额卷产生的优惠卷的使用场景")
    @FieldMapping(desField = "afterSceneList", serialize = false, genericType = "com.xishu.entity.NameAndId")
    @OplogAnnotation(fieldName = "消费后返金额卷产生的优惠卷的使用场景")
    @Lob
    @Column(columnDefinition = "MEDIUMTEXT")
    private String afterSceneJson;

    @ApiModelProperty(value = "最低消费金额")
    @OplogAnnotation(fieldName = "最低消费金额")
    private Double atLeastCost;

    @ApiModelProperty(value = "开始时间")
    @OplogAnnotation(fieldName = "开始时间")
    private Long startTime;

    @ApiModelProperty(value = "结束时间")
    @OplogAnnotation(fieldName = "结束时间")
    private Long endTime;

    @ApiModelProperty(value = "限量，如果是负数，则不限制")
    @OplogAnnotation(fieldName = "限量")
    private Long limitSale;

    @ApiModelProperty(value = "是否可以混合使用")
    @OplogAnnotation(fieldName = "是否可以混合使用")
    private Boolean multiUsed;

    @ApiModelProperty(value = "是否已经下载")
    private Boolean downloaded;

    @ApiModelProperty(value = "是否启动")
    @OplogAnnotation(fieldName = "是否启动")
    private Boolean online;

    @ApiModelProperty(value = "是否适用于堂食")
    @OplogAnnotation(fieldName = "是否适用于堂食")
    private Boolean tangshi;

    @ApiModelProperty(value = "是否适用于外卖")
    @OplogAnnotation(fieldName = "是否适用于外卖")
    private Boolean takeout;

    @ApiModelProperty(value = "优惠卷图片内容，标题描述")
    @Transient
    private String titleMsg;

    @ApiModelProperty(value = "优惠卷图片内容，内容描述")
    @Transient
    private String contentDescription;

    @ApiModelProperty(value = "下载类型，1 横版，2 竖版")
    @Transient
    private int downloadType;

    @ApiModelProperty(value = "是否已经使用过该优惠卷")
    @DefaultValue(defaultValue = "false")
    private Boolean used;

    @ApiModelProperty(value = "优惠券是否已经被兑换了")
    private Boolean exchange;

    @ApiModelProperty(value = "哪一个会员兑换了这张优惠券，如果值是-1，表示店长优惠券")
    private Long customerId;

    @Transient
    @ApiModelProperty(value = "判断会员ID是否为空")
    @Search(isNull = true, fieldName = "customerId")
    private Boolean customerIdNotExist;

    @ApiModelProperty(value = "条形码图片")
    private String barCodeImg;

    @ApiModelProperty(value = "优惠卷绑定的session,同一个会话里面，允许客户端绑定同一个CODE多次，结果不变")
    private String bindingSessionId;

    @ApiModelProperty(value = "绑定的支付订单是哪一个")
    private String bindOrderId;

    @ApiModelProperty(value = "状态， 0表示未生成，1表示生成中，2表示已生成")
    @DefaultValue(defaultValue = "0")
    private Integer status;

    @ApiModelProperty(value = "哪一个分店产生的，适用于消费后优惠卷")
    private Long shopId;

    @ApiModelProperty(value = "哪一个订单产生的，适用于消费后优惠卷")
    private Long createSubOrderId;

    @ApiModelProperty(value = "是否是线上的优惠卷")
    @DefaultValue(defaultValue = "false")
    private Boolean onlineTicket;

    @ApiModelProperty(value = "优惠券是否已经过期")
    @DefaultValue(defaultValue = "false")
    private Boolean expired;

    @ApiModelProperty(value = "配送后的多少天内生效")
    private Integer bindingDays;

    @ApiModelProperty(value = "有效方式，1期间，2配送后天数,默认是1，为了以前的数据兼容")
    @DefaultValue(defaultValue = "1")
    private Integer validType;

    @Transient
    @ApiModelProperty(value = "是否可用")
    private Boolean canUse;

    @Transient
    @ApiModelProperty(value = "过期时间，与endTime一样")
    private Long expiredTime;

    @ApiModelProperty(value = "是否是菜品券")
    private Boolean itemTicket;

    @ApiModelProperty(value = "主菜的ID列表")
    @Transient
    @FieldMapping(desField = "mainItemIdJson", serialize = true, genericType = "java.lang.Long")
    @DefaultValue(defaultValue = "")
    private List<Long> mainItemIdList;

    @FieldMapping(desField = "mainItemIdList", serialize = false, genericType = "java.lang.Long")
    @Lob
    @Column(columnDefinition = "MEDIUMTEXT")
    private String mainItemIdJson;

    @Transient
    @ApiModelProperty(value = "用于显示菜品券关联了哪些菜")
    @DefaultValue(defaultValue = "")
    private List<CompanyMainItem> companyMainItemList;

    @ApiModelProperty(value = "菜品优惠券里面，是否多份有效")
    @DefaultValue(defaultValue = "false")
    private Boolean multiItemValid;

    @ApiModelProperty(value = "是否限量")
    @Transient
    private Boolean limitNumber;

    @ApiModelProperty(value = "优惠券的数量，用于营销的时候显示")
    @Transient
    private Integer ticketNumber;

    @ApiModelProperty(value = "中文描述")
    private String description_zh;

    @ApiModelProperty(value = "英文描述")
    private String description_en;

    @ApiModelProperty(value = "可以兑换的优惠券")
    private Boolean canExchange;

    @ApiModelProperty(value = "语言")
    @Transient
    private String lang;

    @ApiModelProperty(value = "通过excel导入")
    @DefaultValue(defaultValue = "false")
    private Boolean assignByExcel;

    @Override
    public String getOpName() {
        return opName;
    }

    @Override
    public void setOpName(String opName) {
        this.opName = opName;
    }

    @Override
    public String opType() {
        return "優惠券";
    }

    @Override
    public String[] fieldName() {
        return new String[]{"name"};
    }

    public Long getExpiredTime() {
        return endTime;
    }

    public void setExpiredTime(Long expiredTime) {
        this.endTime = expiredTime;
    }
}
